<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改H5游戏')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: jasny-bootstrap-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-game-edit" th:object="${game}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">名字：</label>
                <div class="col-sm-8">
                    <input name="nameEn" th:field="*{nameEn}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">名字(中文)：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">状态：</label>
                <div class="col-sm-8">
                    <select name="status" class="form-control m-b" th:with="type=${@dict.getType('game_status')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{status}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">推荐：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('common_support')}">
                        <input type="radio" th:id="${'recom_' + dict.dictCode}" name="recom" th:value="${dict.dictValue}" th:field="*{recom}">
                        <label th:for="${'recom_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图标：</label>
                <div class="col-sm-8">
                    <input id="icon" name="icon" th:field="*{icon}" class="form-control" type=hidden>
	                <div class="fileinput fileinput-new" data-provides="fileinput">
				        <div class="fileinput-new thumbnail" style="width: 80px; height: 80px;">
				          <img th:src="*{icon}">
				        </div>
				        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 80px; max-height:80px;"></div>
				        <div>
				          <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" class="image" tag="icon"></span>
				          <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
				        </div>
			        </div>
			    </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">链接：</label>
                <div class="col-sm-8">
                    <input name="url" th:field="*{url}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">标签：</label>
                <div class="col-sm-8">
                    <select id="gameTagIds" class="form-control select2-multiple" multiple>
						<option th:each="gameTag:${gameTags}" th:value="${gameTag.id}" th:text="${gameTag.name}" th:selected="${gameTag.flag}"></option>
				    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">分类：</label>
                <div class="col-sm-8">
                    <select id="gameCategoryIds" class="form-control select2-multiple" multiple>
						<option th:each="gameCategory:${gameCategorys}" th:value="${gameCategory.id}" th:text="${gameCategory.name}" th:selected="${gameCategory.flag}"></option>
				    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">同类标签：</label>
                <div class="col-sm-8">
                    <select id="assoTagIds" class="form-control select2-multiple" multiple>
						<option th:each="assoTag:${assoTags}" th:value="${assoTag.id}" th:text="${assoTag.name}" th:selected="${assoTag.flag}"></option>
				    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">生产商：</label>
                <div class="col-sm-8">
                    <input name="producer" th:field="*{producer}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">横竖屏：</label>
                <div class="col-sm-8">
                    <select name="display" class="form-control m-b" th:with="type=${@dict.getType('game_display_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{display}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">国内外：</label>
                <div class="col-sm-8">
                    <select name="domestic" class="form-control m-b" th:with="type=${@dict.getType('game_domestic_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{domestic}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <textarea name="description" class="form-control">[[*{description}]]</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述(短)：</label>
                <div class="col-sm-8">
                    <textarea name="shortDesc" class="form-control">[[*{shortDesc}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图1：</label>
                <div class="col-sm-8">
                    <input id="img1" name="img1" th:field="*{img1}" class="form-control" type="hidden">
	                <div class="fileinput fileinput-new" data-provides="fileinput">
				        <div class="fileinput-new thumbnail" style="width: 234px; height: 133px;">
				          <img th:src="*{img1}">
				        </div>
				        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 234px; max-height: 133px;"></div>
				        <div>
				          <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" class="image" tag="img1"></span>
				          <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
				        </div>
				     </div>
				</div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图2：</label>
                <div class="col-sm-8">
                    <input id="img2" name="img2" th:field="*{img2}" class="form-control" type="hidden">
	                <div class="fileinput fileinput-new" data-provides="fileinput">
				        <div class="fileinput-new thumbnail" style="width: 234px; height: 133px;">
				          <img th:src="*{img2}">
				        </div>
				        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 234px; max-height: 133px;"></div>
				        <div>
				          <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" class="image" tag="img2"></span>
				          <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
				        </div>
				     </div>
				</div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图3：</label>
                <div class="col-sm-8">
                    <input id="img3" name="img3" th:field="*{img3}" class="form-control" type="hidden">
	                <div class="fileinput fileinput-new" data-provides="fileinput">
				        <div class="fileinput-new thumbnail" style="width: 234px; height: 133px;">
				          <img th:src="*{img3}">
				        </div>
				        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 234px; max-height: 133px;"></div>
				        <div>
				          <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" class="image" tag="img3"></span>
				          <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
				        </div>
				     </div>
				 </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图4：</label>
                <div class="col-sm-8">
                    <input id="img4" name="img4" th:field="*{img4}" class="form-control" type="hidden">
	                <div class="fileinput fileinput-new" data-provides="fileinput">
				        <div class="fileinput-new thumbnail" style="width: 234px; height: 133px;">
				          <img th:src="*{img4}">
				        </div>
				        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 234px; max-height: 133px;"></div>
				        <div>
				          <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" class="image" tag="img4"></span>
				          <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
				        </div>
				     </div>
				</div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">图5：</label>
                <div class="col-sm-8">
                    <input id="img5" name="img5" th:field="*{img5}" class="form-control" type="hidden">
	                <div class="fileinput fileinput-new" data-provides="fileinput">
				        <div class="fileinput-new thumbnail" style="width: 234px; height: 133px;">
				          <img th:src="*{img5}">
				        </div>
				        <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 234px; max-height: 133px;"></div>
				        <div>
				          <span class="btn btn-white btn-file"><span class="fileinput-new">选择图片</span><span class="fileinput-exists">更改</span><input type="file" class="image" tag="img5"></span>
				          <a href="#" class="btn btn-white fileinput-exists" data-dismiss="fileinput">清除</a>
				        </div>
				     </div>
				</div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">来源url：</label>
                <div class="col-sm-8">
                    <input name="sourceUrl" th:field="*{sourceUrl}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">来源：</label>
                <div class="col-sm-8">
                    <input name="source" th:field="*{source}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">支持iOS：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('common_support')}">
                        <input type="radio" th:id="${'ios_' + dict.dictCode}" name="ios" th:value="${dict.dictValue}" th:field="*{ios}">
                        <label th:for="${'ios_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">支持安卓：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('common_support')}">
                        <input type="radio" th:id="${'android_' + dict.dictCode}" name="android" th:value="${dict.dictValue}" th:field="*{android}">
                        <label th:for="${'android_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">外链检查：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('common_support')}">
                        <input type="radio" th:id="${'linkCheck_' + dict.dictCode}" name="linkCheck" th:value="${dict.dictValue}" th:field="*{linkCheck}">
                        <label th:for="${'linkCheck_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <th:block th:include="include :: select2-js" />
    <script type="text/javascript">
        var prefix = ctx + "game/game";
        $("#form-game-edit").validate({
            focusCleanup: true
        });
        
        $('.image').on('change.bs.fileinput', function (e) {
        	var file = $(this)[0].files[0];
        	var data = new FormData();
        	var tag = $(this).attr('tag');
	        data.append("file", file);
	        $.ajax({
	            type: "POST",
	            url: ctx + "common/uploadOSS",
	            data: data,
	            cache: false,
	            contentType: false,
	            processData: false,
	            dataType: 'json',
	            success: function(result) {
	            	$('#' + tag).val(result.url);
	            },
	            error: function(error) {
	                alert("图片上传失败。");
	            }
	        });
        	
        });

        function submitHandler() {
            if ($.validate.form()) {
            	
            	var data = $('#form-game-edit').serializeArray();
	        	var gameTagIds = $.form.selectSelects("gameTagIds");
	        	var gameCategoryIds = $.form.selectSelects("gameCategoryIds");
	        	var assoTagIds = $.form.selectSelects("assoTagIds");
	        	
	        	data.push({"name": "gameTagIds", "value": gameTagIds});
	        	data.push({"name": "gameCategoryIds", "value": gameCategoryIds});
	        	data.push({"name": "assoTagIds", "value": assoTagIds});
            	
                $.operate.save(prefix + "/edit", data);
            }
        }
        
        $(function() {
            $('#tag').select2({
                placeholder:"请选择游戏标签",
                allowClear: true
            });
        })

    </script>
</body>
</html>